package com.sy.rabbit.publish;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created by uu on 2017/1/9.
 */
public class EmitLog {

    private static  final  String EXCHANGE_NAME = "logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare(EXCHANGE_NAME,"fanout");

        for (int i = 0; i < 5; i++) {
            String messgae = "Hello World! " + i;
            channel.basicPublish(EXCHANGE_NAME,"",null,messgae.getBytes());
            System.out.print("[X] Sent'" + messgae + "'");
        }
        channel.close();
        connection.close();
    }
}
